var comboTools;
DepartmentOcCombo = Ext.extend(Ext.Window,
{
	formPanel : null,
	DepartmentOcGrid : null,
	constructor : function(a) {
		Ext.applyIf(this, a);
		this.initUIComponents();
		DepartmentOcCombo.superclass.constructor.call(
				this, {
					layout : "fit",
					items : this.formPanel,
					modal : true,
					id : "DepartmentOcComboWin",
					title : "工艺信息",
					iconCls : "menu-productionPlanCoating",
					width : 700,
					autoHeight : true,
					buttonAlign : "center",
					autoScroll : true,
					buttons : this.buttons
				});
	},
	initUIComponents : function() {
		comboTools = this.comboTools;
		this.initDepartmentOcInfoPanel();
		this.formPanel = new Ext.FormPanel(
				{
					url :"",
					layout : "form",
					id : "DepartmentOcCombo",
					border : false, 
					height:380,
					formId : "DepartmentOcComboId",
					items : [
							
							{
								layout : "column",
								items : [ {
									columnWidth : 1,// 第1列
									layout : "form",
									border : false,
									bodyStyle : "padding:5px;",
									items : [ this.DepartmentOcGrid ]
								} ]
							} 
					]
				});
		this.buttons = [ { 
			text : "确定",
			iconCls : "btn-save",
			scope : this,
			handler : function(){
				this.save();
			}
		}, {
			text : "取消",
			iconCls : "btn-cancel",
			scope : this,
			handler : function() {
				lcocId = "";
				this.close();
			}
		} ];
		
		this.save = function(){
			var h = Ext.getCmp("DepartmentOcInfoGrid");
			if(h.getSelectionModel().getSelected()==null){
				Ext.ux.Toast.msg("信息", "请选择外协公司！");
				return;
			}
//			Ext.getCmp("outsourcingCompany").setValue(lcocId);
			var lcN=parseInt(lcocName);
			//判断是否为纯数字！
			if(!isNaN(lcN)){
				comboTools.setValue("’"+lcocName);
			}else{
				comboTools.setValue(lcocName);
			}
			comboTools.hiddenField.value=lcocId;
			
			lccocId=Ext.getCmp("DepartmentOcInfoGrid").getSelectionModel().getSelected().data.oCompanyId;
//			l.reload({
//			params : {
//				start : 0,
//				limit : 25,
//				oCompanyId : lccocId
//				}
//			});
			this.close();
		}
	}
});
//选择工艺panal
DepartmentOcCombo.prototype.initDepartmentOcInfoPanel = function() {
	var search = initSearchPanel();
	var grid = initGridPanel();
	this.DepartmentOcGrid = new Ext.Panel({
		id : "DepartmentOcInfoPanel",
		title : "请选择工艺",
		iconCls : "menu-appuser",
		layout : "border",
		autoScroll : true,
		height : 330,
		items : [ search, grid ]
	});
	function initSearchPanel() {
		var searchPanel = new Ext.Panel({
			id:'DepartmentOcInfoSearchPanel',
			region : "north",
			height : 35,
			frame : false,
			border : false,
			layout : "hbox",
			layoutConfig : {
				padding : "5",
				align : "middle"
			},
			defaults : {
				xtype : "label",
				border : false,
				margins : {
					top : 0,
					right : 4,
					bottom : 4,
					left : 4
				}
			},
			items : [ 
				{
					text:"公司编号"
				},	{
					xtype : "textfield",
					name : "Q_oCompanyNo_S_LK"
				},  {
					text : "公司名称"
				}, {
					xtype : "textfield",
					name : "Q_oCompanyName_S_LK"
				} ,
			{
				xtype : "button",
				text : "查询",
				iconCls : "search",
				scope : this,
    		    handler : onSearch
			}, {
				xtype : "button",
				text : "清空",
				scope : this,
				iconCls : "reset",
				handler :DepartmentOcCombo.reset
			} ]
		});
		return searchPanel;
	} ;
	function onSearch(c) {
		var a = Ext.getCmp("DepartmentOcInfoSearchPanel");
		var e = Ext.getCmp("DepartmentOcInfoGrid"); 
			var b = e.getStore();
			var d1=a.findById("Q_oCompanyName_S_LK"); 
			var d2=a.findById("Q_oCompanyNo_S_LK"); 
			var c = Ext.urlDecode("Q_oCompanyName_S_LK="+d1.getValue()+"&Q_oCompanyNo_S_LK="+d2.getValue());
			c.start = 0;
			c.limit = b.baseParams.limit;
			b.baseParams = c;
			e.getBottomToolbar().moveFirst();
	};
	function initGridPanel() {
		var b = new Ext.data.Store({
			proxy : new Ext.data.HttpProxy({
				url : __ctxPath	+ "/promanage/listOutSourcingCompany.do"
			}),
			reader : new Ext.data.JsonReader({
				root : "result",
				totalProperty : "totalCounts",
				fields : [ {
					name : "oCompanyId",
					type : "long"
				}, "oCompanyNo","oCompanyName","oCompanyDesc","oCompanyTel","oCompanyFax","oCompanyAdd","oCompanyEmail","oCompanyPostCode","oCompanyProRange","oCompanyLinkman","oCompanyLmTel","oCompanyMark"]
			}),
			remoteSort : true
		});
		b.setDefaultSort("oCompanyId", "asc");
		b.load({
			params : {
				start : 0,
				limit : 25
			}
		});
		var e = new Ext.grid.CheckboxSelectionModel({
			singleSelect : true,
			listeners : {
				rowselect : function(){
					lcocId = Ext.getCmp("DepartmentOcInfoGrid").getSelectionModel().getSelected().data.oCompanyId; 
					lcocName = Ext.getCmp("DepartmentOcInfoGrid").getSelectionModel().getSelected().data.oCompanyName; 
				}
			}
		});
		var a = new Ext.grid.ColumnModel({
		columns : [ e, new Ext.grid.RowNumberer(), 
			 {
					header:"oCompanyId",
					dataIndex:"oCompanyId",
					hidden:true
			},{
				header : "公司编号",
				dataIndex : "oCompanyNo" 
			}, {
				header : "公司名称",
				dataIndex : "oCompanyName",
				width : 100
			}, {
				header : "公司传真",
				dataIndex : "oCompanyFax",
				width : 80
			},{
				header : "联系人",
				dataIndex : "oCompanyLinkman",
				width : 60
			}],
			defaults : {
				sortable : true,
				menuDisabled : true,
				width : 100
				}
		});
		var gridPanel = new Ext.grid.GridPanel({
			id : "DepartmentOcInfoGrid",
			store : b,
			region : "center",
			autoScroll : true,
			shim : true,
			trackMouseOver : true,
			disableSelection : false,
			loadMask : true,
			cm : a,
			sm : e,
			viewConfig : {
				forceFit : true,
				enableRowBody : false,
				showPreview : false
			},
			bbar : new HT.PagingBar({
				store : b
			})
		});
		gridPanel.addListener("rowdblclick", function(){
			var lcN=parseInt(lcocName);
			//判断是否为纯数字！
			if(!isNaN(lcN)){
				comboTools.setValue("’"+lcocName);
			}else{
				comboTools.setValue(lcocName);
			}
			comboTools.hiddenField.value=lcocId;
			lccocId=Ext.getCmp("DepartmentOcInfoGrid").getSelectionModel().getSelected().data.oCompanyId;
//			l.reload({
//			params : {
//				start : 0,
//				limit : 25,
//				oCompanyId : lccocId
//				}
//			});
			Ext.getCmp("DepartmentOcComboWin").close();
		});
		return gridPanel;
	}
};
DepartmentOcCombo.reset = function(a) {
	var a = Ext.getCmp("DepartmentOcCombo");
	a.getForm().reset();
};